package net.jueb.frameworkDemo.se.protostuff;

import io.protostuff.LinkedBuffer;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.runtime.RuntimeSchema;

/**
 * 序列号性能比较
 * https://github.com/eishay/jvm-serializers/wiki
 * @author juebanlin
 */
public class Test {

	private static RuntimeSchema<Person> schema = RuntimeSchema.createFrom(Person.class);
	public static void main(String[] args) {
		/**
		*序列化
		*/
		Person crab = new Person();  
		crab.setName("kaka");  
		//参数三缓冲器
		byte[] bytes = ProtostuffIOUtil.toByteArray(crab,schema,LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
		/**
		 *反序列化
		 */
		// 空对象
		Person newCrab = schema.newMessage();
		ProtostuffIOUtil.mergeFrom(bytes,newCrab,schema);
		System.out.println("Hi, My name is " + newCrab.getName());
	}
}
